/*
 * @Author: zhengzhuang
 * @Date: 2020-08-24 18:08:22
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-04-12 11:19:05
 * @Description: 扫码收款(城际出行)
 * @FilePath: /C20Driver/lib/pages/intercity_car/get_on_by_ticket.dart
 */
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/service/request.dart';
import 'dart:convert' as convert;
import 'package:C20Driver/widget/spinkit.dart';

class GetOnByTicket extends StatelessWidget {
  final String id;
  final String routerId;
  final String driverId;
  GetOnByTicket({this.id, this.routerId, this.driverId});

  Future _getCode() async {
    return await Request.getSmallProgramCode(
        timeId: id, routeId: routerId, driverId: driverId);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('扫码收款'),
      ),
      backgroundColor: Colors.white,
      body: Container(
          child: FutureBuilder(
              future: _getCode(),
              builder: (BuildContext context, AsyncSnapshot snapshot) {
                if (snapshot.hasData) {
                  Uint8List _urlImage =
                      convert.base64.decode(snapshot.data.toString());
                  return Center(
                    child: Container(
                      width: ScreenUtil().setWidth(500.0),
                      height: ScreenUtil().setWidth(500.0),
                      color: Colors.black12,
                      child: _imgWidget(_urlImage),
                    ),
                  );
                } else {
                  return Spinkit();
                }
              })),
    );
  }

  Widget _imgWidget(Uint8List _urlImage) {
    try {
      return Image.memory(_urlImage);
    } catch (e) {
      return Container();
    }
  }
}
